package com.zxq.web.back.controller;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zxq.common.controller.BaseController;
import com.zxq.common.pojo.ApiResponse;
import com.zxq.common.pojo.ApiResponseEnum;
import com.zxq.common.util.ConstatFinalUtil;
import com.zxq.common.util.PageInfoUtil;
import com.zxq.lawenf.pojo.AApproval;
import com.zxq.lawenf.pojo.ACase;
import com.zxq.lawenf.pojo.ACate;
import com.zxq.lawenf.pojo.AHistory;
import com.zxq.lawenf.service.ILawEnfDbService;
import com.zxq.users.pojo.AAdmins;
import com.zxq.users.pojo.AUsers;

/**
 * 	执法模块示例代码操作
 * 	@author 章晓琦
 */
@Controller
@RequestMapping("/back/lawEnf/")
public class LawEnfBackController extends BaseController
{
	@Resource
	private ILawEnfDbService lawEnfDbService;
	
	/*====分类模板表开始====*/
	/**
	 * 分类模板列表页面
	 * @return
	 */
	@RequestMapping("/cateList")
	public String cateList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ACate> response = this.lawEnfDbService.findCondListCateService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		request.setAttribute("response", response.toJSON());
		return "/back/lawEnf/cateList";
	}

	/**
	 * 打开添加分类模板页面
	 * @return
	 */
	@RequestMapping("/cateInsert")
	public String cateInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateInsert--");
		return "/back/lawEnf/cateInsert";
	}
	
	/**
	 * 添加分类模板提交操作
	 * @return
	 */
	@RequestMapping(value = "/cateInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cateInsertSubmit(HttpServletRequest request, String pubTimeStr , ACate cate, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateInsertSubmit--");
		/* 为对象赋值 */
		cate.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		cate.setCreateTime(new Date());
		cate.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneCateService(cate);
		ConstatFinalUtil.SYS_LOGGER.info("--分类模板添加返回结果:{}--",response.toJSON());
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新分类模板页面
	 * @return
	 */
	@RequestMapping("/cateUpdate")
	public String cateUpdate(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACate> response = this.lawEnfDbService.findOneCateService(condMap);
		/* 存储request */
		request.setAttribute("response", response.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/lawEnf/cateUpdate";
		}
		return "/back/lawEnf/cateInfo";
	}
	
	/**
	 * 添加分类模板提交操作
	 * @return
	 */
	@RequestMapping(value = "/cateUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cateUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateUpdateSubmit--");
		ApiResponse<Object> apiResponseRes = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACate> response = this.lawEnfDbService.findOneCateService(condMap);
		/* 获取java对象 */
		ACate cate = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String name = request.getParameter("name");
			String url = request.getParameter("url");
			String cateType = request.getParameter("cateType");
			String content = request.getParameter("content");
			String status = request.getParameter("status");
			String pubTimeStr = request.getParameter("pubTimeStr");
			
			/* 设置属性 */
			cate.setName(name);
			cate.setUrl(url);
			cate.setCateType(Byte.valueOf(cateType));
			cate.setContent(content);
			cate.setStatus(Byte.valueOf(status));
			
			cate.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			cate.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = lawEnfDbService.updateOneCateService(cate);
			ConstatFinalUtil.SYS_LOGGER.info("--分类模板添加返回结果:{}--",dbRes.toJSON());
			return dbRes.toJSON().toJSONString(); 
		}
		return apiResponseRes.toJSON().toJSONString();
	}
	
	/**
	 * 分类模板批量操作
	 * @return
	 */
	@RequestMapping(value = "/cateBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cateBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ACate> apiResponseDb = this.lawEnfDbService.findOneCateService(condMap);
					ACate cate = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					cate.setStatus(Byte.valueOf(status));
					cate.setPubTime(new Date());
					
					ApiResponse<Object> cateClassResponse = this.lawEnfDbService.updateOneCateService(cate);
					if(cateClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====分类模板表结束====*/
	
	/*====申请单表开始====*/
	/**
	 * 申请单列表页面
	 * @return
	 */
	@RequestMapping("/approvalList")
	public String approvalList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*---- 额外增加的新条件 ----*/
		/*---- usersId ----*/
		String usersId = request.getParameter("usersId");
		if(usersId == null)
		{
			usersId = "";
		}
		condMap.put("usersId", usersId);
		request.setAttribute("usersId", usersId);
		
		/*---- adminsId ----*/
		String adminsId = request.getParameter("adminsId");
		if(adminsId == null)
		{
			adminsId = "";
		}
		condMap.put("adminsId", adminsId);
		request.setAttribute("adminsId", adminsId);
		
		/*---- appType ----*/
		String appType = request.getParameter("appType");
		if(appType == null)
		{
			appType = "";
		}
		condMap.put("appType", appType);
		request.setAttribute("appType", appType);
		
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<AApproval> response = this.lawEnfDbService.findCondListApprovalService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		request.setAttribute("response", response.toJSON());
		return "/back/lawEnf/approvalList";
	}

	/**
	 * 打开添加申请单页面
	 * @return
	 */
	@RequestMapping("/approvalInsert")
	public String approvalInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalInsert--");
		return "/back/lawEnf/approvalInsert";
	}
	
	/**
	 * 添加申请单提交操作
	 * @return
	 */
	@RequestMapping(value = "/approvalInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String approvalInsertSubmit(HttpServletRequest request, String pubTimeStr , AApproval approval, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalInsertSubmit--");
		/* 为对象赋值 */
		approval.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		approval.setCreateTime(new Date());
		approval.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneApprovalService(approval);
		ConstatFinalUtil.SYS_LOGGER.info("--申请单添加返回结果:{}--",response.toJSON());
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新申请单页面
	 * @return
	 */
	@RequestMapping("/approvalUpdate")
	public String approvalUpdate(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AApproval> response = this.lawEnfDbService.findOneApprovalService(condMap);
		/* 存储request */
		request.setAttribute("response", response.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/lawEnf/approvalUpdate";
		}
		return "/back/lawEnf/approvalInfo";
	}
	
	/**
	 * 添加申请单提交操作
	 * @return
	 */
	@RequestMapping(value = "/approvalUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String approvalUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalUpdateSubmit--");
		AAdmins admins = (AAdmins) this.findObjfromSession(request, "admins");
		
		ApiResponse<Object> apiResponseRes = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AApproval> response = this.lawEnfDbService.findOneApprovalService(condMap);
		/* 获取java对象 */
		AApproval approval = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String status = request.getParameter("status");
			String note = request.getParameter("note");
			/* 设置属性 */
			approval.setStatus(Byte.valueOf(status));
			approval.setNote(note);
			
			/* 设置管理员 */
			approval.setAdminsId(admins.getId());
			
			approval.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = this.lawEnfDbService.updateOneApprovalService(approval);
			ConstatFinalUtil.SYS_LOGGER.info("--申请单添加返回结果:{}--",dbRes.toJSON());
			return dbRes.toJSON().toJSONString(); 
		}
		return apiResponseRes.toJSON().toJSONString();
	}
	
	/**
	 * 申请单批量操作
	 * @return
	 */
	@RequestMapping(value = "/approvalBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String approvalBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<AApproval> apiResponseDb = this.lawEnfDbService.findOneApprovalService(condMap);
					AApproval approval = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					approval.setStatus(Byte.valueOf(status));
					approval.setPubTime(new Date());
					
					ApiResponse<Object> approvalClassResponse = this.lawEnfDbService.updateOneApprovalService(approval);
					if(approvalClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====申请单表结束====*/
	
	/*====案件表开始====*/
	/**
	 * 案件列表页面
	 * @return
	 */
	@RequestMapping("/caseList")
	public String caseList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1List--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		
		/*---- usersId ----*/
		String usersId = request.getParameter("usersId");
		if(usersId == null)
		{
			usersId = "";
		}
		condMap.put("usersId", usersId);
		request.setAttribute("usersId", usersId);
		
		/*---- depUseId ----*/
		String depUseId = request.getParameter("depUseId");
		if(depUseId == null)
		{
			depUseId = "";
		}
		condMap.put("depUseId", depUseId);
		request.setAttribute("depUseId", depUseId);
		
		/*---- usersId ----*/
		String dirUseId = request.getParameter("dirUseId");
		if(dirUseId == null)
		{
			dirUseId = "";
		}
		condMap.put("dirUseId", dirUseId);
		request.setAttribute("dirUseId", dirUseId);
		
		/*---- usersId ----*/
		String appType = request.getParameter("appType");
		if(appType == null)
		{
			appType = "";
		}
		condMap.put("appType", appType);
		request.setAttribute("appType", appType);
		
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ACase> response = this.lawEnfDbService.findCondListCaseService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		request.setAttribute("response", response.toJSON());
		return "/back/lawEnf/caseList";
	}

	/**
	 * 打开添加案件页面
	 * @return
	 */
	@RequestMapping("/caseInsert")
	public String caseInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1Insert--");
		return "/back/lawEnf/caseInsert";
	}
	
	/**
	 * 添加案件提交操作
	 * @return
	 */
	@RequestMapping(value = "/caseInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String caseInsertSubmit(HttpServletRequest request, String pubTimeStr , ACase case1, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1InsertSubmit--");
		/* 为对象赋值 */
		case1.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		case1.setCreateTime(new Date());
		case1.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneCaseService(case1);
		ConstatFinalUtil.SYS_LOGGER.info("--案件添加返回结果:{}--",response.toJSON());
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新案件页面
	 * @return
	 */
	@RequestMapping("/caseUpdate")
	public String caseUpdate(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1Update--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACase> response = this.lawEnfDbService.findOneCaseService(condMap);
		/* 存储request */
		request.setAttribute("response", response.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/lawEnf/caseUpdate";
		}
		return "/back/lawEnf/caseInfo";
	}
	
	/**
	 * 添加案件提交操作
	 * @return
	 */
	@RequestMapping(value = "/caseUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String caseUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1UpdateSubmit--");
		ApiResponse<Object> apiResponseRes = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACase> response = this.lawEnfDbService.findOneCaseService(condMap);
		/* 获取java对象 */
		ACase case1 = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String name = request.getParameter("name");
			String capital = request.getParameter("capital");
			String stYear = request.getParameter("stYear");
			String edYear = request.getParameter("edYear");
			String status = request.getParameter("status");
			String pubTimeStr = request.getParameter("pubTimeStr");
			String content = request.getParameter("content");
			/* 设置属性 */
			case1.setName(name);
			case1.setContent(content);
			case1.setStatus(Byte.valueOf(status));
			
			case1.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			case1.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = this.lawEnfDbService.updateOneCaseService(case1);
			ConstatFinalUtil.SYS_LOGGER.info("--案件添加返回结果:{}--",dbRes.toJSON());
			return dbRes.toJSON().toJSONString(); 
		}
		return apiResponseRes.toJSON().toJSONString();
	}
	
	/**
	 * 案件批量操作
	 * @return
	 */
	@RequestMapping(value = "/caseBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String caseBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--case1Batch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ACase> apiResponseDb = this.lawEnfDbService.findOneCaseService(condMap);
					ACase case1 = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					case1.setStatus(Byte.valueOf(status));
					case1.setPubTime(new Date());
					
					ApiResponse<Object> case1ClassResponse = this.lawEnfDbService.updateOneCaseService(case1);
					if(case1ClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====案件表结束====*/
	
	/*====历史表开始====*/
	/**
	 * 历史列表页面
	 * @return
	 */
	@RequestMapping("/historyList")
	public String historyList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		
		/*---- hisType ----*/
		String hisType = request.getParameter("hisType");
		if(hisType == null)
		{
			hisType = "";
		}
		condMap.put("hisType", hisType);
		request.setAttribute("hisType", hisType);
		
		/*---- relaId ----*/
		String relaId = request.getParameter("relaId");
		if(relaId == null)
		{
			relaId = "";
		}
		condMap.put("relaId", relaId);
		request.setAttribute("relaId", relaId);
		
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<AHistory> response = this.lawEnfDbService.findCondListHistoryService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		request.setAttribute("response", response.toJSON());
		return "/back/lawEnf/historyList";
	}

	/**
	 * 打开添加历史页面
	 * @return
	 */
	@RequestMapping("/historyInsert")
	public String historyInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyInsert--");
		return "/back/lawEnf/historyInsert";
	}
	
	/**
	 * 添加历史提交操作
	 * @return
	 */
	@RequestMapping(value = "/historyInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String historyInsertSubmit(HttpServletRequest request, String pubTimeStr , AHistory history, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyInsertSubmit--");
		/* 为对象赋值 */
		history.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		history.setCreateTime(new Date());
		history.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneHistoryService(history);
		ConstatFinalUtil.SYS_LOGGER.info("--历史添加返回结果:{}--",response.toJSON());
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新历史页面
	 * @return
	 */
	@RequestMapping("/historyUpdate")
	public String historyUpdate(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AHistory> response = this.lawEnfDbService.findOneHistoryService(condMap);
		/* 存储request */
		request.setAttribute("response", response.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/lawEnf/historyUpdate";
		}
		return "/back/lawEnf/historyInfo";
	}
	
	/**
	 * 添加历史提交操作
	 * @return
	 */
	@RequestMapping(value = "/historyUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String historyUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyUpdateSubmit--");
		ApiResponse<Object> apiResponseRes = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AHistory> response = this.lawEnfDbService.findOneHistoryService(condMap);
		/* 获取java对象 */
		AHistory history = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String name = request.getParameter("name");
			String capital = request.getParameter("capital");
			String stYear = request.getParameter("stYear");
			String edYear = request.getParameter("edYear");
			String status = request.getParameter("status");
			String pubTimeStr = request.getParameter("pubTimeStr");
			String content = request.getParameter("content");
			/* 设置属性 */
			history.setContent(content);
			history.setStatus(Byte.valueOf(status));
			
			history.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			history.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = this.lawEnfDbService.updateOneHistoryService(history);
			ConstatFinalUtil.SYS_LOGGER.info("--历史添加返回结果:{}--",dbRes.toJSON());
			return dbRes.toJSON().toJSONString(); 
		}
		return apiResponseRes.toJSON().toJSONString();
	}
	
	/**
	 * 历史批量操作
	 * @return
	 */
	@RequestMapping(value = "/historyBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String historyBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<AHistory> apiResponseDb = this.lawEnfDbService.findOneHistoryService(condMap);
					AHistory history = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					history.setStatus(Byte.valueOf(status));
					history.setPubTime(new Date());
					
					ApiResponse<Object> historyClassResponse = this.lawEnfDbService.updateOneHistoryService(history);
					if(historyClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====历史表结束====*/
}
